//
//  ByUIProductEvaluateVC.m
//  oc_knowledge
//
//  Created by pro on 17/1/19.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUIProductEvaluateVC.h"

// cell
#import "ByCellProductEvaluateCommon.h" 

// view
#import "ByViewDetailEvaluateHeader.h"


@interface ByUIProductEvaluateVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) ByViewDetailEvaluateHeader *header;

@property (nonatomic, copy) NSArray *items;

@end

@implementation ByUIProductEvaluateVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"评价";
    
    [self addLeftBackBarButtonItem];
    
    [self simData];
    [self createTableView];
}
- (void)simData {
    
    ByModelProductEvaluate *model1 = [[ByModelProductEvaluate alloc] init];
    model1.icon = @"";
    model1.nickname = @"任性不认命";
    model1.create_time = @"2017-1-2";
    model1.sku_desc = @"尺码：大码；颜色分类：七色花";
    model1.content = @"东西非常好，卖家非常细心得回答我所有的问题，我深感欣慰，嗯嗯嗯";
    
    ByModelProductEvaluate *model2 = [[ByModelProductEvaluate alloc] init];
    model2.icon = @"";
    model2.nickname = @"蒙氏塔城";
    model2.create_time = @"2017-5-6";
    model2.sku_desc = @"尺码：小码；颜色分类：橘色";
    model2.content = @"差评差评，什么卖家啊，出了问题一点都不负责任";
    
    ByModelProductEvaluate *model3 = [[ByModelProductEvaluate alloc] init];
    model3.icon = @"";
    model3.nickname = @"Zzzz";
    model3.create_time = @"2017-7-22";
    model3.sku_desc = @"尺码：中码；颜色分类：粉红";
    model3.content = @"只能说还行吧，物流较慢，商家回复的也比较慢";
    
    self.items = @[model1, model2, model3];
}

#pragma mark - 懒加载
- (ByViewDetailEvaluateHeader *)header {
    
    if (!_header) {
        _header = [[ByViewDetailEvaluateHeader alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        _header.tags = @[@"质量不错",
                         @"舒适",
                         @"好看",
                         @"胖胖",
                         @"飞飞",
                         @"NONONO",
                         @"服务好"];
        __weak typeof(self) weakself = self;
        _header.moreClickBlock = ^ {
            [weakself.table reloadData];
        };
    }
    return _header;
}

#pragma mark - 创建视图
// 创建表视图
- (void)createTableView {
    
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    self.table.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];    
}

#pragma mark - UITableViewDataSource UITableViewDelegate
// 设置组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.items.count;
}
// 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
// 设置单元格属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ByCellProductEvaluateCommon *cell = [tableView dequeueReusableCellWithIdentifier:@"evaluateCell"];
    if (cell == nil) {
        cell = [[ByCellProductEvaluateCommon alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"evaluateCell"];
    }
    
    ByCellLayoutProductEvaluateCommon *layout = [[ByCellLayoutProductEvaluateCommon alloc] init];
    layout.model = self.items[indexPath.section];
    cell.layout = layout;
    
    return cell;
    
}
// 设置单元格行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    ByCellLayoutProductEvaluateCommon *layout = [[ByCellLayoutProductEvaluateCommon alloc] init];
    layout.model = self.items[indexPath.section];
    return layout.cellFrame.size.height;
}
// 设置组头高
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return self.header.height;
    }
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return self.header;
    }
    return [UIView new];
}
// 设置组尾高
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

// 单元格点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}



@end
